/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ejb.dao;

import entidades.Consumo;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.Query;

/**
 *
 * @author paulo
 */
@Stateless
public class ConsumoDAO extends GenericoJPADAO<Consumo> implements ConsumoDAOLocal {

    @Override
    public List<Consumo> buscarTodos() {
        Query q = em.createQuery("SELECT object(c) FROM Consumo AS c");
        return q.getResultList();
    }

    @Override
    public int contador() {
        Query q = em.createQuery("SELECT count(c) FROM Consumo AS c");
        return (Integer) q.getSingleResult();
    }

    @Override
    public List<Consumo> findConsumosByTransporte(String patente) {
        Query q = em.createQuery("SELECT object(c) FROM Consumo AS c"
                + "WHERE c.patente = :patente");
        q.setParameter("patente", patente);
        return q.getResultList();
    }
}
